﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using System.IO;

namespace IPR_TrainExamSys_TY.Employee
{
    public partial class FrmEmployeeInfo : Form
    {
        Model.T_PublicEmployee mSelEmployee = new Model.T_PublicEmployee();
        Model.T_PublicEmployeeXLJY mSelEmployeeXLJY = new Model.T_PublicEmployeeXLJY();
        Model.T_PublicEmployeeGWJL mSelEmployeeGWJL = new Model.T_PublicEmployeeGWJL();
        Model.T_PublicEmployeeJNDJ mSelEmployeeJNDJ = new Model.T_PublicEmployeeJNDJ();
        Model.T_PublicEmployeeHJJL mSelEmployeeHJJL = new Model.T_PublicEmployeeHJJL();

        public FrmEmployeeInfo()
        {
            InitializeComponent();
            tbEmployeeIdSearch.Text = BaseClass.CLoginInfo.LoginEmployee.EmployeeId;
            tbEmployeeNameSearch.Text = BaseClass.CLoginInfo.LoginEmployee.EmployeeName;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            superTabControl1.SelectedTabIndex = 0;
            mSelEmployee = new Model.T_PublicEmployee();
            Cursor.Current = Cursors.WaitCursor;
            string sWhere = " 1=1 ";
            if (tbEmployeeIdSearch.Text.Trim() != "")
                sWhere += " and EmployeeId='" + tbEmployeeIdSearch.Text.Trim() + "'";
            if (tbEmployeeNameSearch.Text.Trim() != "")
                sWhere += " and EmployeeName = '" + tbEmployeeNameSearch.Text.Trim() + "' ";
            mSelEmployee = new T_PublicEmployee().GetModel(sWhere);
            if (mSelEmployee != null)
            {
                EmployeeId.Text = mSelEmployee.EmployeeId;
                EmployeeName.Text = mSelEmployee.EmployeeName;
                tbGWHGZSBH.Text = mSelEmployee.GWHGZSBH;
                if ((mSelEmployee.Sex != null) && (mSelEmployee.Sex != ""))
                    if (mSelEmployee.Sex == "男") Sex.Text = "男";
                    else Sex.Text = "女";
                if ((mSelEmployee.Birthday != null) && (mSelEmployee.Birthday != ""))
                    try
                    {
                        Birthday.Value = Convert.ToDateTime(mSelEmployee.Birthday);
                    }
                    catch
                    {
                    }
                Nation.Text = mSelEmployee.Nation;
                if ((mSelEmployee.EntryTime != null) && (mSelEmployee.EntryTime != ""))
                    try
                    {
                        EntryTime.Value = Convert.ToDateTime(mSelEmployee.EntryTime);
                    }
                    catch
                    {
                    }
                Education.Text = mSelEmployee.Education;
                Job.Text = mSelEmployee.Job;
                JB.Text = mSelEmployee.JB;
                RYLY.Text = mSelEmployee.RYLY;
                WorkShop.Text = mSelEmployee.WorkShop;
                ClassGroup.Text = mSelEmployee.ClassGroup;

                if ((mSelEmployee.LicenceDate2 != null) && (mSelEmployee.LicenceDate2 != ""))
                    try
                    {
                        LicenceDate2.Value = Convert.ToDateTime(mSelEmployee.LicenceDate2);
                    }
                    catch
                    {
                    }

                if ((mSelEmployee.IsClassLeader != null) && (mSelEmployee.IsClassLeader != ""))
                    if (mSelEmployee.IsClassLeader == "是") IsClassLeader.Text = "是";
                    else IsClassLeader.Text = "否";
                else IsClassLeader.Text = "否";

                if (mSelEmployee.Photograph != null && mSelEmployee.Photograph.ToString() != "")
                {
                    Image img = reph(mSelEmployee.Photograph);//将二进制数组转换成Image类型
                    pictureBox1.Image = img;
                }
            }
            else
            {
                MessageBox.Show("人员信息档案不存在！", "查询结果不存在");
            }
            Cursor.Current = Cursors.Default; ;
        }

        public Image reph(byte[] streambyte)
        {
            MemoryStream ms = new MemoryStream(streambyte);
            Image img = Image.FromStream(ms);
            return img;
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.png)|*.png";
            openFileDialog1.Title = "选择要导入的图片";
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
            }
        }

        private void btnAddJCXX_Click(object sender, EventArgs e)
        {
            Model.T_PublicEmployee mAddEmployee = new Model.T_PublicEmployee();
            mAddEmployee.EmployeeId = EmployeeId.Text.Trim();
            mAddEmployee.EmployeeName = EmployeeName.Text.Trim();
            mAddEmployee.GWHGZSBH = tbGWHGZSBH.Text.Trim();
            mAddEmployee.Sex = Sex.Text;
            mAddEmployee.Birthday = Birthday.Value.ToString("yyyy-MM-dd");
            mAddEmployee.Education = Education.Text.Trim();
            mAddEmployee.Nation = Nation.Text.Trim();
            mAddEmployee.LicenceDate2 = LicenceDate2.Value.ToString("yyyy-MM-dd");
            mAddEmployee.EntryTime = EntryTime.Value.ToString("yyyy-MM-dd");
            mAddEmployee.JB = JB.Text.Trim();
            mAddEmployee.Job = Job.Text.Trim();
            mAddEmployee.RYLY = RYLY.Text.Trim();
            mAddEmployee.WorkShop = WorkShop.Text.Trim();
            mAddEmployee.ClassGroup = ClassGroup.Text.Trim();
            mAddEmployee.IsClassLeader = IsClassLeader.Text;

            if (pictureBox1.Image != null)
            {
                MemoryStream ms = new MemoryStream();
                pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] b = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(b, 0, b.Length);
                ms.Close();
                mAddEmployee.Photograph = b;
            }


            if (EmployeeId.Text.Trim() == "")
            {
                MessageBox.Show("请输入工号", "数据不完整");
                return;
            }
            if (tbGWHGZSBH.Text.Trim() == "")
            {
                MessageBox.Show("请输入岗位合格证书编号", "数据不完整");
                return;
            }
            string sWhere = " EmployeeId='" + EmployeeId.Text.Trim() + "' or GWHGZSBH='" + tbGWHGZSBH.Text.Trim() + "'";
            Model.T_PublicEmployee selmPe = new T_PublicEmployee().GetModel(sWhere);
            if (selmPe != null)
            {
                MessageBox.Show("工号或者岗位合格证书编号重复！", "员工信息重复");
                return;
            }
            long lr = new T_PublicEmployee().Add(mAddEmployee);
            if (lr > 0)
                MessageBox.Show("数据添加完成", "添加完成");
        }

        private void btnUpdateJCXX_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "update T_PublicEmployee set GWHGZSBH='" + tbGWHGZSBH.Text.Trim() + "',EmployeeName='" + EmployeeName.Text.Trim() + "',Sex='" + Sex.Text.Trim() + "',Birthday='" + Birthday.Value.ToString("yyyy-MM-dd") + "',Education='" + Education.Text.Trim() + "'," +
                    " Nation='" + Nation.Text.Trim() + "',LicenceDate2='" + LicenceDate2.Value.ToString("yyyy-MM-dd") + "',Job='" + Job.Text.Trim() + "',JB='" + JB.Text.Trim() + "',EntryTime='" + EntryTime.Value.ToString("yyyy-MM-dd") + "',RYLY='" + RYLY.Text.Trim() + "',WorkShop='" + WorkShop.Text.Trim() + "',ClassGroup='" + ClassGroup.Text.Trim() + "',IsClassLeader='" + IsClassLeader.Text + "' " +
                    " where EmployeeId='" + EmployeeId.Text.Trim() + "' ";
                if (new T_Public().ExecuteSql(sql) > 0)
                if (pictureBox1.Image != null)
                {
                    MemoryStream ms = new MemoryStream();
                    pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] b = new byte[ms.Length];
                    ms.Position = 0;
                    ms.Read(b, 0, b.Length);
                    ms.Close();
                    if (new T_PublicEmployee().UpdatePhoto(EmployeeId.Text.Trim(), b))
                    {
                        MessageBox.Show("人员信息修改完成", "修改完成");
                    }
                }
                else
                    MessageBox.Show("人员信息修改完成", "修改完成");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "数据修改错误");
            }
        }

        private void superTabControl1_SelectedTabChanged(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
        {
            if (EmployeeId.Text.Trim() == "") return;
            DataSet ds = new DataSet();
            string sWhere = " 1=1 and EmployeeID='" +EmployeeId.Text.Trim() + "'";
            try
            {
                switch (superTabControl1.SelectedTabIndex)
                {
                    case 0:
                        break;
                    case 1:
                        superGridControl1.PrimaryGrid.Rows.Clear();
                        ds = new T_PublicEmployeeXLJY().GetList(sWhere);
                        if (ds != null)
                            if (ds.Tables.Count > 0)
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    superGridControl1.PrimaryGrid.DataSource = ds.Tables[0];
                                }
                        break;
                    case 2:
                        superGridControl2.PrimaryGrid.Rows.Clear();
                        ds = new T_PublicEmployeeGWJL().GetList(sWhere);
                        if (ds != null)
                            if (ds.Tables.Count > 0)
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    superGridControl2.PrimaryGrid.DataSource = ds.Tables[0];
                                }
                        break;
                    case 3:
                        superGridControl3.PrimaryGrid.Rows.Clear();
                        ds = new T_PublicEmployeeJNDJ().GetList(sWhere);
                        if (ds != null)
                            if (ds.Tables.Count > 0)
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    superGridControl3.PrimaryGrid.DataSource = ds.Tables[0];
                                }
                        break;
                    case 4:

                        superGridControl4.PrimaryGrid.Rows.Clear();
                        ds = new T_PublicEmployeeHJJL().GetList(sWhere);
                        if (ds != null)
                            if (ds.Tables.Count > 0)
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    superGridControl4.PrimaryGrid.DataSource = ds.Tables[0];
                                }
                        break;
                    case 5:

                        superGridControl5.PrimaryGrid.Rows.Clear();
                        string sql = "select ksls,gh,xm,ksjg,kssj,a.paperBh,c.paperName,WorkShop,ClassGroup,Job,ExamAddr,a.GWHGZSBH," +
                            " LocomotiveNo,Sex,Nation,Native,PoliticalStatus,NL,JB,a.pxkssj,a.pxjssj from pe_llksjg a " +
                            " left join T_PublicEmployee b on a.GWHGZSBH=b.GWHGZSBH  and a.gh=b.EmployeeId " +
                            " left join pe_paperMa c on a.paperBh=c.paperBh " +
                            " where 1=1 ";
                        if (tbEmployeeIdSearch.Text.Trim() != "")
                            sql += "and gh='" + tbEmployeeIdSearch.Text.Trim() + "' ";
                        if (tbEmployeeNameSearch.Text.Trim() != "")
                            sql += " and xm like '%" + tbEmployeeNameSearch.Text.Trim() + "%'";
                        sql += " order by a.id ";
                        ds = new T_Public().Query(sql);
                        if (ds != null)
                            if (ds.Tables.Count > 0)
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    superGridControl5.PrimaryGrid.DataSource = ds.Tables[0];
                                }
                        break;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }

        private void btnAddXLJY_Click(object sender, EventArgs e)
        {
            try
            {
                Model.T_PublicEmployeeXLJY mEmployeeXLJY = new Model.T_PublicEmployeeXLJY();
                mEmployeeXLJY.EmployeeID = EmployeeId.Text.Trim();
                mEmployeeXLJY.EmployeeName = EmployeeName.Text.Trim();
                mEmployeeXLJY.JBXX = tbJBXX.Text.Trim();
                mEmployeeXLJY.ZYMC = tbZYMC.Text.Trim();
                mEmployeeXLJY.XLCC = tbXLCC.Text.Trim();
                mEmployeeXLJY.XXFS = tbXXFS.Text.Trim();
                if (chbRXSJ.Checked) mEmployeeXLJY.RXSJ = dtpRXSJ.Value.ToString("yyyy-MM-dd");
                if (chbBYSJ.Checked) mEmployeeXLJY.BYSJ = dtpBYSJ.Value.ToString("yyyy-MM-dd");
                if (new T_PublicEmployeeXLJY().Add(mEmployeeXLJY) > 0)
                {
                    MessageBox.Show("学历教育增加完成", "增加完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 1;
                }
            }
            catch(Exception exc)
            {
                MessageBox.Show("学历教育增加失败\r\n"+exc.Message, "增加失败");
            }
        }

        private void superGridControl1_CellClick(object sender, DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs e)
        {
            try
            {
                mSelEmployeeXLJY = new Model.T_PublicEmployeeXLJY();
                mSelEmployeeXLJY.FID = e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value == null ? 0 : long.Parse(e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value.ToString());
                mSelEmployeeXLJY.EmployeeID = e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value.ToString();
                mSelEmployeeXLJY.EmployeeName = e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value.ToString();
                mSelEmployeeXLJY.JBXX = e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value.ToString();
                mSelEmployeeXLJY.ZYMC = e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value.ToString();
                mSelEmployeeXLJY.XLCC = e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value.ToString();
                mSelEmployeeXLJY.XXFS = e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value.ToString();
                mSelEmployeeXLJY.RXSJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value.ToString();
                mSelEmployeeXLJY.BYSJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value.ToString();

                tbJBXX.Text = mSelEmployeeXLJY.JBXX;
                tbZYMC.Text = mSelEmployeeXLJY.ZYMC;
                tbXLCC.Text = mSelEmployeeXLJY.XLCC;
                tbXXFS.Text = mSelEmployeeXLJY.XXFS;
                try
                {
                    dtpRXSJ.Value = mSelEmployeeXLJY.RXSJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeXLJY.RXSJ);
                }
                catch { }
                try
                {
                    dtpBYSJ.Value = mSelEmployeeXLJY.BYSJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeXLJY.BYSJ);
                }
                catch { }

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }

        }

        private void btnUpdateXLJY_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeXLJY == null) return;
            mSelEmployeeXLJY.EmployeeID = EmployeeId.Text.Trim();
            mSelEmployeeXLJY.EmployeeName = EmployeeName.Text.Trim();
            mSelEmployeeXLJY.JBXX = tbJBXX.Text.Trim();
            mSelEmployeeXLJY.ZYMC = tbZYMC.Text.Trim();
            mSelEmployeeXLJY.XLCC = tbXLCC.Text.Trim();
            mSelEmployeeXLJY.XXFS = tbXXFS.Text.Trim();
            if (chbRXSJ.Checked) mSelEmployeeXLJY.RXSJ = dtpRXSJ.Value.ToString("yyyy-MM-dd");
            if (chbBYSJ.Checked) mSelEmployeeXLJY.BYSJ = dtpBYSJ.Value.ToString("yyyy-MM-dd");
            try
            {
                if (new T_PublicEmployeeXLJY().Update(mSelEmployeeXLJY))
                {
                    MessageBox.Show("学历教育修改完成", "修改完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 1;
                }
            }
            catch(Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnDelXLJY_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeXLJY == null)
            {
                return;
            }
            try
            {
                if (new T_PublicEmployeeXLJY().Delete(mSelEmployeeXLJY.FID))
                {
                    MessageBox.Show("数据删除完成", "删除完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 1;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void buttonX8_Click(object sender, EventArgs e)
        {
            try
            {
                Model.T_PublicEmployeeGWJL mEmployeeXLJY = new Model.T_PublicEmployeeGWJL();
                mEmployeeXLJY.EmployeeID = EmployeeId.Text.Trim();
                mEmployeeXLJY.EmployeeName = EmployeeName.Text.Trim();
                try
                {
                    mEmployeeXLJY.BDSJ = dtpBDSJ.Value.ToString("yyyy-MM-dd");
                }
                catch
                {
                }
                mEmployeeXLJY.BDQZM = tbBDQZM.Text.Trim();
                mEmployeeXLJY.BDHZM = tbBDHZM.Text.Trim();
                mEmployeeXLJY.BZ = tbBZGWJL.Text.Trim();

                if (new T_PublicEmployeeGWJL().Add(mEmployeeXLJY) > 0)
                {
                    MessageBox.Show("岗位经历增加完成", "增加完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 2;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("岗位经历增加失败\r\n" + exc.Message, "增加失败");
            }
        }

        private void superGridControl2_CellClick(object sender, DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs e)
        {
            try
            {
                mSelEmployeeGWJL = new Model.T_PublicEmployeeGWJL();
                mSelEmployeeGWJL.FID = e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value == null ? 0 : long.Parse(e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value.ToString());
                mSelEmployeeGWJL.EmployeeID = e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value.ToString();
                mSelEmployeeGWJL.EmployeeName = e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value.ToString();
                mSelEmployeeGWJL.BDSJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value.ToString();
                mSelEmployeeGWJL.BDQZM = e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value.ToString();
                mSelEmployeeGWJL.BDHZM = e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value.ToString();
                mSelEmployeeGWJL.BZ = e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value.ToString();


                tbBDQZM.Text = mSelEmployeeGWJL.BDQZM;
                tbBDHZM.Text = mSelEmployeeGWJL.BDHZM;
                tbBZGWJL.Text = mSelEmployeeGWJL.BZ; 
                try
                {
                    dtpBDSJ.Value = mSelEmployeeGWJL.BDSJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeGWJL.BDSJ);
                }
                catch { } 

            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnUpdateGWJL_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeGWJL == null) return;
            mSelEmployeeGWJL.EmployeeID = EmployeeId.Text.Trim();
            mSelEmployeeGWJL.EmployeeName = EmployeeName.Text.Trim();
            mSelEmployeeGWJL.BDSJ = dtpBDSJ.Value.ToString("yyyy-MM-dd");
            mSelEmployeeGWJL.BDQZM =tbBDQZM.Text.Trim();
            mSelEmployeeGWJL.BDHZM = tbBDHZM.Text.Trim();
            mSelEmployeeGWJL.BZ = tbBZGWJL.Text.Trim();

            try
            {
                if (new T_PublicEmployeeGWJL().Update(mSelEmployeeGWJL))
                {
                    MessageBox.Show("岗位经历修改完成", "修改完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 2;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnDelGWJL_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeGWJL == null)
            {
                return;
            }
            try
            {
                if (new T_PublicEmployeeGWJL().Delete(mSelEmployeeGWJL.FID))
                {
                    MessageBox.Show("数据删除完成", "删除完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 2;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void buttonX11_Click(object sender, EventArgs e)
        {
            try
            {
                Model.T_PublicEmployeeJNDJ mEmployeeJNDJ = new Model.T_PublicEmployeeJNDJ();
                mEmployeeJNDJ.EmployeeID = EmployeeId.Text.Trim();
                mEmployeeJNDJ.EmployeeName = EmployeeName.Text.Trim();
                if (chbCJ.Checked) mEmployeeJNDJ.CJ = dtpCJ.Value.ToString("yyyy-MM-dd");
                if (chbZJ.Checked) mEmployeeJNDJ.ZJ = dtpZJ.Value.ToString("yyyy-MM-dd");
                if (chbGJ.Checked) mEmployeeJNDJ.GJ = dtpGJ.Value.ToString("yyyy-MM-dd");
                if (chbJS.Checked) mEmployeeJNDJ.JS = dtpJS.Value.ToString("yyyy-MM-dd");
                if (chbGJJS.Checked) mEmployeeJNDJ.GJJS = dtpGJJS.Value.ToString("yyyy-MM-dd"); 
                mEmployeeJNDJ.BZ = tbBZJNDJ.Text.Trim(); 
                if (new T_PublicEmployeeJNDJ().Add(mEmployeeJNDJ) > 0)
                {
                    MessageBox.Show("技能等级增加完成", "增加完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 3;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("技能等级增加失败\r\n" + exc.Message, "增加失败");
            }
        }

        private void btnUpdateJNDJ_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeJNDJ == null) return;
            mSelEmployeeJNDJ.EmployeeID = EmployeeId.Text.Trim();
            mSelEmployeeJNDJ.EmployeeName = EmployeeName.Text.Trim();
            if (chbCJ.Checked) mSelEmployeeJNDJ.CJ = dtpCJ.Value.ToString("yyyy-MM-dd");
            if (chbZJ.Checked) mSelEmployeeJNDJ.ZJ = dtpZJ.Value.ToString("yyyy-MM-dd");
            if (chbGJ.Checked) mSelEmployeeJNDJ.GJ = dtpGJ.Value.ToString("yyyy-MM-dd");
            if (chbJS.Checked) mSelEmployeeJNDJ.JS = dtpJS.Value.ToString("yyyy-MM-dd");
            if (chbGJJS.Checked) mSelEmployeeJNDJ.GJJS = dtpGJJS.Value.ToString("yyyy-MM-dd");
            mSelEmployeeJNDJ.BZ = tbBZJNDJ.Text.Trim();
            try
            {
                if (new T_PublicEmployeeJNDJ().Update(mSelEmployeeJNDJ))
                {
                    MessageBox.Show("信息修改完成", "修改完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 3;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void superGridControl3_CellClick(object sender, DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs e)
        {
            try
            {
                mSelEmployeeJNDJ = new Model.T_PublicEmployeeJNDJ();
                mSelEmployeeJNDJ.FID = e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value == null ? 0 : long.Parse(e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value.ToString());
                mSelEmployeeJNDJ.EmployeeID = e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value.ToString();
                mSelEmployeeJNDJ.EmployeeName = e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value.ToString();
                mSelEmployeeJNDJ.CJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value.ToString();
                mSelEmployeeJNDJ.ZJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value.ToString();
                mSelEmployeeJNDJ.GJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value.ToString();
                mSelEmployeeJNDJ.JS = e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value.ToString();
                mSelEmployeeJNDJ.GJJS = e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value.ToString();
                mSelEmployeeJNDJ.BZ = e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value.ToString();
  
                try
                {
                    dtpCJ.Value = mSelEmployeeJNDJ.CJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeJNDJ.CJ);
                }
                catch { }
                try
                {
                    dtpZJ.Value = mSelEmployeeJNDJ.ZJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeJNDJ.ZJ);
                }
                catch { }
                try
                {
                    dtpGJ.Value = mSelEmployeeJNDJ.GJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeJNDJ.GJ);
                }
                catch { }
                try
                {
                    dtpJS.Value = mSelEmployeeJNDJ.JS == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeJNDJ.JS);
                }
                catch { }
                try
                {
                    dtpGJJS.Value = mSelEmployeeJNDJ.GJJS == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeJNDJ.GJJS);
                }
                catch { }
                tbBZJNDJ.Text = mSelEmployeeJNDJ.BZ;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnDelJNDJ_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeJNDJ == null)
            {
                return;
            }
            try
            {
                if (new T_PublicEmployeeJNDJ().Delete(mSelEmployeeJNDJ.FID))
                {
                    MessageBox.Show("数据删除完成", "删除完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 3;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnAddHJJL_Click(object sender, EventArgs e)
        {
            try
            {
                Model.T_PublicEmployeeHJJL mEmployeeHJJL = new Model.T_PublicEmployeeHJJL();
                mEmployeeHJJL.EmployeeID = EmployeeId.Text.Trim();
                mEmployeeHJJL.EmployeeName = EmployeeName.Text.Trim();
                mEmployeeHJJL.SJ = dtpHJLSJ.Value.ToString("yyyy-MM-dd");
                mEmployeeHJJL.JBDW = tbJBDW.Text.Trim();
                mEmployeeHJJL.JSLB = tbJSLB.Text.Trim();
                mEmployeeHJJL.JSMC = tbJSMC.Text.Trim();
                mEmployeeHJJL.QDMC = tbQDMC.Text.Trim();
                mEmployeeHJJL.HJCH = tbHJCH.Text.Trim();
                 
                if (new T_PublicEmployeeHJJL().Add(mEmployeeHJJL) > 0)
                {
                    MessageBox.Show("信息增加完成", "增加完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 4;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("信息增加失败\r\n" + exc.Message, "增加失败");
            }
        }

        private void btnUpdateHJJL_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeHJJL == null) return;
            mSelEmployeeHJJL.EmployeeID = EmployeeId.Text.Trim();
            mSelEmployeeHJJL.EmployeeName = EmployeeName.Text.Trim();
            mSelEmployeeHJJL.SJ = dtpHJLSJ.Value.ToString("yyyy-MM-dd");
            mSelEmployeeHJJL.JBDW = tbJBDW.Text.Trim();
            mSelEmployeeHJJL.JSLB = tbJSLB.Text.Trim();
            mSelEmployeeHJJL.JSMC = tbJSMC.Text.Trim();
            mSelEmployeeHJJL.QDMC = tbQDMC.Text.Trim();
            mSelEmployeeHJJL.HJCH = tbHJCH.Text.Trim();
            try
            {
                if (new T_PublicEmployeeHJJL().Update(mSelEmployeeHJJL))
                {
                    MessageBox.Show("信息修改完成", "修改完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 4;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnDelHJJL_Click(object sender, EventArgs e)
        {
            if (mSelEmployeeHJJL == null)
            {
                return;
            }
            try
            {
                if (new T_PublicEmployeeHJJL().Delete(mSelEmployeeHJJL.FID))
                {
                    MessageBox.Show("数据删除完成", "删除完成");
                    superTabControl1.SelectedTabIndex = 0;
                    superTabControl1.SelectedTabIndex = 4;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void superGridControl4_CellClick(object sender, DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs e)
        {
            try
            {
                mSelEmployeeHJJL = new Model.T_PublicEmployeeHJJL();
                mSelEmployeeHJJL.FID = e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value == null ? 0 : long.Parse(e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value.ToString());
                mSelEmployeeHJJL.EmployeeID = e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value.ToString();
                mSelEmployeeHJJL.EmployeeName = e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 2).Value.ToString();
                mSelEmployeeHJJL.SJ = e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 3).Value.ToString();
                mSelEmployeeHJJL.JBDW = e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 4).Value.ToString();
                mSelEmployeeHJJL.JSLB = e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 5).Value.ToString();
                mSelEmployeeHJJL.JSMC = e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 6).Value.ToString();
                mSelEmployeeHJJL.QDMC = e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value.ToString();
                mSelEmployeeHJJL.HJCH = e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value == null ? "" : e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value.ToString();

                try
                {
                    dtpHJLSJ.Value = mSelEmployeeHJJL.SJ == "" ? DateTime.Now : Convert.ToDateTime(mSelEmployeeHJJL.SJ);
                }
                catch { }

                tbJBDW.Text = mSelEmployeeHJJL.JBDW;
                tbJSLB.Text = mSelEmployeeHJJL.JSLB;
                tbJSMC.Text = mSelEmployeeHJJL.JSMC;
                tbQDMC.Text = mSelEmployeeHJJL.QDMC;
                tbHJCH.Text = mSelEmployeeHJJL.HJCH;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "提示");
            }
        }

        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            if (EmployeeId.Text.Trim() == "")
            {
                MessageBox.Show("请先根据工号或者姓名查询履历信息","提示");
                return;
            }
            string sfile=Application.StartupPath+"\\ExcelModel\\教育履历表模板.xls";
            if (!File.Exists(sfile))
            {
                MessageBox.Show("导出的文件模板不存在，请先检查文件模板","提示");
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "(*.xls)|*.xls";
            sfd.Title = "选择要导出的文件保存位置";
            string sSaveFilePath = "";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                sSaveFilePath = sfd.FileName;
            }
            else return;


            DataTable dtEmployee = new DataTable();
            DataTable dtEmployeeXLJY = new DataTable();
            DataTable dtEmployeeGWJL = new DataTable();
            DataTable dtEmployeeJNDJ = new DataTable();
            DataTable dtEmployeeHJJL = new DataTable();
            DataTable dtExamInfo = new DataTable();

            try
            {

                #region 获取导出数据
                DataSet ds = new DataSet();
                string sWhere = " 1=1 and EmployeeID='" + EmployeeId.Text.Trim() + "'";

                ds = new T_PublicEmployee().GetList(sWhere);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtEmployee = ds.Tables[0];
                        }


                ds = new T_PublicEmployeeXLJY().GetList(sWhere);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtEmployeeXLJY  = ds.Tables[0];
                        }

                ds = new T_PublicEmployeeGWJL().GetList(sWhere);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtEmployeeGWJL = ds.Tables[0];
                        }

                ds = new T_PublicEmployeeJNDJ().GetList(sWhere);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtEmployeeJNDJ = ds.Tables[0];
                        }

                ds = new T_PublicEmployeeHJJL().GetList(sWhere);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtEmployeeHJJL = ds.Tables[0];
                        }

                string sql = "select ksls,gh,xm,ksjg,kssj,a.paperBh,c.paperName,WorkShop,ClassGroup,Job,ExamAddr,a.GWHGZSBH," +
                    " LocomotiveNo,Sex,Nation,Native,PoliticalStatus,NL,JB,a.pxkssj,a.pxjssj from pe_llksjg a " +
                    " left join T_PublicEmployee b on a.GWHGZSBH=b.GWHGZSBH  and a.gh=b.EmployeeId " +
                    " left join pe_paperMa c on a.paperBh=c.paperBh " +
                    " where 1=1 ";
                if (EmployeeId.Text.Trim() != "")
                    sql += "and gh='" + EmployeeId.Text.Trim() + "' "; 
                sql += " order by a.id ";
                ds = new T_Public().Query(sql);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            dtExamInfo = ds.Tables[0];
                        }

                #endregion

                string sResult = Common.ATNPOIHelper.ExportForModul(sfile, sSaveFilePath, dtEmployee, dtEmployeeXLJY, dtEmployeeGWJL, dtEmployeeJNDJ, dtEmployeeHJJL, dtExamInfo);
                switch (sResult.Split('#')[0])
                {
                    case "0":
                        MessageBox.Show("导出成功,文件导出位置为\r\n" + sSaveFilePath, "导出成功");
                        break;
                    default:
                        MessageBox.Show(sResult.Split('#')[1], "导出失败");
                        break;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("导出错误！\r\n" + exc.Message, "导出错误");
            }



        }
    }
}
